package com.wen.moudle.Managers;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.wen.entry.Result;
import com.wen.entry.bean.Information;
import com.wen.entry.bean.WeaponAndSkill;
import com.wen.moudle.Account;
import com.wen.moudle.abstractManager;

import java.util.List;

public class InformationManager extends abstractManager {
    public InformationManager(Account account) {
        super(account);
    }

    public Result<Information> getInfo(){
        HttpResponse response = HttpRequest.get(config.get("角色信息"))
                .cookie(getCookies())
                .execute();
        return JSONUtil.toBean(response.body(), new TypeReference<Result<Information>>() {},false);
    }

    // 获取体力
    public Integer getPhysical(){
        Result<Information> info = getInfo();
        return info.getData().getPhysical();
    }

    // 获取金钱
    public Integer getMoney(){
        Result<Information> info = getInfo();
        return info.getData().getMoney();
    }

    public List<WeaponAndSkill> getWeapon(){
        HttpResponse response = HttpRequest.get(config.get("武器列表"))
                .cookie(getCookies()).execute();
        return JSONUtil.toBean(response.body(),new TypeReference<Result<List<WeaponAndSkill>>>(){},false).getData();
    }

    public List<WeaponAndSkill> getSkill(){
        HttpResponse response = HttpRequest.get(config.get("技能列表"))
                .cookie(getCookies()).execute();
        return JSONUtil.toBean(response.body(),new TypeReference<Result<List<WeaponAndSkill>>>(){},false).getData();
    }

    public Result<String> levelUp(WeaponAndSkill weaponAndSkill){
        HttpResponse response = HttpRequest.get(config.get("升级")+weaponAndSkill.getId())
                .cookie(getCookies()).execute();
        return JSONUtil.toBean(response.body(),
                new TypeReference<Result<String>>(){},
                false);
    }

    // 签到
    public Result<String> checkIn(){
        HttpResponse response = HttpRequest.post(config.get("签到"))
                .cookie(getCookies())
                .execute();
        return JSONUtil.toBean(response.body(), new TypeReference<Result<String>>() {},false);
    }
}
